<?php

require_once 'cartcred.modelo.class.php';

class CartCredControl {

    function CartCredControl() {

        if (isset($_POST['action']) && $_POST['action'] == "cartcred_insert") {

            if ($_POST['ban_ent'] == NULL || $_POST['number'] == NULL || $_POST['name'] == NULL || $_POST['flag'] == NULL) {
                echo "Preencha todos os campos";

                return false;
            }

            $cartcredModelo = new CartCredModelo();
            $cartcredModelo->setBan_ent($_POST['ban_ent']);
            $cartcredModelo->setNumber($_POST['number']);
			$cartcredModelo->setName($_POST['name']);
			$cartcredModelo->setFlag($_POST['flag']);

            $cartcredModelo->insert();

            header("Location: ../index.php");
        }

        if (isset($_POST['action']) && $_POST['action'] == "cartcred_update") {

            if ($_POST['ban_ent'] == NULL || $_POST['number'] == NULL || $_POST['name'] == NULL || $_POST['flag'] == NULL) {
                echo "Preencha todos os campos";

                return false;
            }
			
            $cartcredModelo = new CartCredModelo();
            $cartcredModelo->setBan_ent($_POST['ban_ent']);
            $cartcredModelo->setNumber($_POST['number']);
			$cartcredModelo->setName($_POST['name']);
			$cartcredModelo->setFlag($_POST['flag']);

            $cartcredModelo->updateBan_ent();
            $cartcredModelo->updateNumber();
			$cartcredModelo->updateName();
			$cartcredModelo->updateFlag();

            header("Location: ../index.php");
        }

        if (isset($_GET['action']) && $_GET['action'] == "cartcred_delete") {

            $cartcredModelo = new CartCredModelo();
            $cartcredModelo->setId($_GET['id']);

            $cartcredModelo->delete();

            header("Location: ../index.php");
        }

    }

    function selectCartCred($id) {
        $cartcredModelo = new CartCredModelo();
        $array = $cartcredModelo->select("WHERE id = ".$id);
        return $array;
    }

    function selectAll() {
        $cartcredModelo = new CartCredModelo();
        $array = $cartcredModelo->select("");
        return $array;
    }

}

?>

